package com.xiaofeng.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.xiaofeng.common.Const;
import com.xiaofeng.pojo.Human_Resource;
import com.xiaofeng.service.iservice.Human_ResourceService;


@Controller("humanResourceAction")
public class HumanResourceAction implements ModelDriven<Human_Resource>,RequestAware,SessionAware{

	@Autowired
	private Human_ResourceService human;
	
	private Map<String, Object> sessionMap;
	@Override
	public void setSession(Map<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
		
	}
	private int page; 

	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}

	private Map<String, Object> requestMap;
	@Override
	public void setRequest(Map<String, Object> requestMap) {
		this.requestMap = requestMap;
		
	}

	private Human_Resource human_Resource = new Human_Resource();
	@Override
	public Human_Resource getModel() {
		
		return human_Resource;
	}
	public String save(){			
		return  human.insert(human_Resource);	
	}
	public String delete(){	
	return	human.delete(human_Resource);		
	}
	public String update(){
		//String msg = Const.ERROR;
		
		//msg = Const.SUCCESS;
		return human.update(human_Resource);
	}
	public String findAll(){
		int page = 1;
		int num = 1;
		int size = 3;
		String msg = Const.ERROR;
		List<Human_Resource> list = human.findall(num,size);
		if(list != null && list.size() > 0){
			requestMap.put("list", list);
			sessionMap.put("page",page);
			msg = Const.SUCCESS;
		}
		return msg;
	}

	public String findpage(){
		String msg = Const.ERROR;
		int a = human.findByPagno(page).getPageNo();		
		List<Human_Resource> list = human.findByPagno(a).getList();	
		if(list != null && list.size() > 0){
			
			requestMap.put("list", list);			
			requestMap.put("page", a);
			msg = Const.SUCCESS;		
		}
		return msg;
		
	}
	public String findById(){
		String msg = Const.ERROR;
		Human_Resource humanResource = human.findById(human_Resource.getId());
		if(humanResource != null){
			requestMap.put("humanResource",humanResource);
			msg = Const.SUCCESS;
		}
		return msg;
	}
	public String load(){
		String msg = Const.ERROR;
		Human_Resource humanResource = human.findById(human_Resource.getId());
		System.out.println(humanResource);
		if(humanResource != null){
			requestMap.put("humanResource",humanResource);
			msg = Const.SUCCESS;
		}
		return msg;
	}
}
